package org.dbi.beans;

import java.util.HashMap;

import org.dbi.exceptions.AttribGroupAlreadyExistsException;
import org.dbi.exceptions.KeyAlreadyExistsException;
import org.dbi.logger.ErrorLogger;

public class Key {
	private String naam = "";
	private HashMap<String, AttributeGroup> attributeGroups;
	private ErrorLogger logger = ErrorLogger.getLogger(getClass().getName());

	public Key(String naam) {
		this.naam = naam;
		this.attributeGroups = new HashMap<String, AttributeGroup>();
		logger.info("Key: " + naam + " aangemaakt");
	}

	public String getNaam() {
		return naam;
	}

	public HashMap<String, AttributeGroup> getAttributeGroups() {
		return attributeGroups;
	}

	public void addSingleAttributeGroup(AttributeGroup attributeGroup) {
		try {
			if (!attributeGroups.containsKey(attributeGroup.getNaam())) {
				attributeGroups.put(attributeGroup.getNaam(), attributeGroup);
				logger.info("AttributeGroup: " + attributeGroup.getNaam() + " toegevoegd aan Key: " + getNaam());
			} else
				throw new AttribGroupAlreadyExistsException(attributeGroup.getNaam());
		} catch (AttribGroupAlreadyExistsException e) {
			logger.severe(e.getMessage());
		}
	}

	public void addMultipleAttributeGroups(HashMap<String, AttributeGroup> attributeGroups) {
		if (attributeGroups.size() != 0 && attributeGroups != null) {
			for (AttributeGroup attribGroup : attributeGroups.values()) {
				addSingleAttributeGroup(attribGroup);
			}
		}
	}

}
